package com.xushi.service.impl;

import com.xushi.dao.VeriCodeRepository;
import com.xushi.model.VeriCode;
import com.xushi.service.VeriCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * Created by Sun on 2018/6/2.
 */
@Service("veriCodeService")
@Transactional
public class VeriCodeServiceImpl implements VeriCodeService {

    @Autowired
    private VeriCodeRepository veriCodeDao;

    @Override
    public VeriCode addVeriCode(String phoneNumber, String code) {
        Timestamp currTime = new Timestamp(System.currentTimeMillis());
        VeriCode veriCode = new VeriCode();
        veriCode.setPhoneNumber(phoneNumber);
        veriCode.setCode(code);
        veriCode.setTime(currTime);
        return veriCodeDao.save(veriCode);
    }

    @Override
    public VeriCode getVeriCodeByPhoneNumber(String phoneNumber) {
        return veriCodeDao.findByPhoneNumber(phoneNumber);
    }
}
